﻿using ET_DbCommon.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ET_DbCommon.DAL
{
    public static class DeviceDAL
    {
        public static List<DeviceModel> GetDevice()
        {
            List<DeviceModel> devices = new List<DeviceModel>();
            string sql = "*";
            devices = AllDefineDAL.GetElementCollection <DeviceModel>(sql);
            return devices;
        }

        public static List<DeviceModel> GetDeviceByLine(string LineName)
        {
            List<DeviceModel> devices = new List<DeviceModel>();
            string sql = "*";
            devices = AllDefineDAL.GetElementCollection<DeviceModel>(sql).FindAll(x => x.LineName == LineName || x.LineName == "None");
            return devices;
        }

        public static List<DeviceModel> GetDeviceByDeviceType(int deviceTypeID)
        {
            using(var conn = MySqlHelper.GetConnection())
            {
                string where = $"WHERE DeviceTypeId = {deviceTypeID}";
                return MySQLExt.GetByWhere<DeviceModel>(conn, where).ToList();
            }
        }
    }
}
